<template>
  <div class="app-box">
    <Layout ref="runBox"
            title="CMSAutoCreate终端"
            temp="Temp1"
            @handleSuccessMqttMessage="handleSuccessMqttMessage"
            @handleErrorMqttMessage="handleErrorMqttMessage"
            :ic="ic"
            :url="url"
            :readID="true"
            :readIC="true"></Layout>
  </div>
</template> 
<script>
import Layout from '../core/layout.vue'
import { GSAConstants } from '@/utils/access'
import {
  log,
} from '@/utils/message'
export default {
  components: { Layout },
  data () {
    return {
      ic: GSAConstants().TOPIC_AUTO_CREATE.ic,
      url: GSAConstants().TOPIC_AUTO_CREATE.url
    }
  },
  created () {

  },
  mounted () {

  },
  methods: {
    showMsg (msg, type) {
      this.$refs.runBox.showMsg(msg, type)

    },
    // 读卡成功的回调信息  
    handleSuccessMqttMessage (messageObject) {
      log('cms-auto-create 开始处理业务' + JSON.stringify(messageObject) + ', current IC :' + this.ic)
      if (messageObject.ic === this.ic) {
        if (messageObject.dt[4] !== '') {
          this.showMsg(messageObject.dt[4], 'blue')
        } else {
          this.showMsg(messageObject.dt[3] + '作业处理成功， 请取CMS', 'green')
        }

        // 清除表单
        this.$refs.runBox.handleSuccess()
      }
    },
    handleErrorMqttMessage (messageObject) {
      log('cms-auto-create ERROR开始处理业务' + JSON.stringify(messageObject) + ', current IC :' + this.ic)
      if (messageObject.ic === this.ic) {
        // 清除表单
        this.$refs.runBox.handleSuccess()
      }
    }
  },
}
</script>

<style scoped>
.app-box {
  padding: 0px;
}
</style>
